﻿#ifndef PST_SURFACEELECTRICFIELDMAPSIDEBARDATA_H
#define PST_SURFACEELECTRICFIELDMAPSIDEBARDATA_H

#include <QObject>
#include <QList>
#include "FieldGraphGenerator.h"
#include "TextFileParser.h"
#include "BaseModule/GlobalHelper.h"

namespace pst
{
    class SurfaceElectricFieldMapSidebarData :public QObject
    {
        Q_OBJECT

    public:
        SurfaceElectricFieldMapSidebarData(QObject* parent = nullptr) :QObject(parent) {}
        ~SurfaceElectricFieldMapSidebarData() {}

        void setGraphName(const QString& graphName) { m_graphName = graphName; }
        QString getGraphName() const { return m_graphName; }

        void setIsGraphNameRenamed(bool isRenamed) { m_isGraphNameRenamed = isRenamed; };
        bool getIsGraphNameRenamed() { return m_isGraphNameRenamed; };

        void setIsShowActor(bool isShowActor) { m_isShowActor = isShowActor; }
        bool getIsShowActor() const { return m_isShowActor; }

        void setAllPointArray(QList<FieldGraphGenerator::ArrayInformation> allPointArray) { m_allPointArray = allPointArray; }
        QList<FieldGraphGenerator::ArrayInformation> getAllPointArray() const { return m_allPointArray; }

        void setAllCellArray(QList<FieldGraphGenerator::ArrayInformation> allCellArray) { m_allCellArray = allCellArray; }
        QList<FieldGraphGenerator::ArrayInformation> getAllCellArray() const { return m_allCellArray; }

        void setCurrentScalarArray(FieldGraphGenerator::ArrayInformation currentScalarArray) { m_currentScalarArray = currentScalarArray; }
        FieldGraphGenerator::ArrayInformation getCurrentScalarArray() const { return m_currentScalarArray; }

        void setCurrentScalarArrayComp(int currentScalarArrayComp) { m_currentScalarArrayComp = currentScalarArrayComp; }
        int getCurrentScalarArrayComp() const { return m_currentScalarArrayComp; }

        bool getIsLog() const { return m_isLog; }
        void setIsLog(bool isLog) { m_isLog = isLog; }

        bool getIsNormalized() const { return m_isNormalized; }
        void setIsNormalized(bool isNormalized) { m_isNormalized = isNormalized; }

        void setDataSource(const QString& dataSource) { m_dataSource = dataSource; };
        QString getDataSource() const { return m_dataSource; };

        void PrintSelf()
        {
            qInfo() << "m_graphName:" << m_graphName;
            qInfo() << "m_isGraphNameRenamed:" << m_isGraphNameRenamed;
            qInfo() << "m_isShowActor:" << m_isShowActor;
            qInfo() << "m_allPointArray:";
            for (const FieldGraphGenerator::ArrayInformation& i : m_allPointArray)
            {
                i.printArrayInformation();
            }
            qInfo() << "\n m_allCellArray:";
            for (const FieldGraphGenerator::ArrayInformation& i : m_allCellArray)
            {
                i.printArrayInformation();
            }
            qInfo() << "\n m_currentScalarArray:";
            m_currentScalarArray.printArrayInformation();
            qInfo() << "\n m_isLog:" << m_isLog;
            qInfo() << "\n m_isNormalized:" << m_isNormalized;
            qInfo() << "m_dataSource:" << m_dataSource;
        }

        /// @brief 文件写出至工程文件
        QDomElement& writeToProjectFile(QDomDocument* doc, QDomElement* element, bool isdiso = false)
        {
            QDomElement _ThreeDSurfacePlotSidebarDataRoot = doc->createElement("ThreeDSurfacePlotSidebarData");

            GlobalHelperInstance->createDomElement(doc, &_ThreeDSurfacePlotSidebarDataRoot, "GraphName", m_graphName);
            GlobalHelperInstance->createDomElement(doc, &_ThreeDSurfacePlotSidebarDataRoot, "IsGraphNameRenamed", QString::number(m_isGraphNameRenamed));
            GlobalHelperInstance->createDomElement(doc, &_ThreeDSurfacePlotSidebarDataRoot, "IsShowActor", QString::number(m_isShowActor));

            GlobalHelperInstance->createDomElement(doc, &_ThreeDSurfacePlotSidebarDataRoot, "CurrentScalarArrayComp", QString::number(m_currentScalarArrayComp));
            GlobalHelperInstance->createDomElement(doc, &_ThreeDSurfacePlotSidebarDataRoot, "IsLog", QString::number(m_isLog));
            GlobalHelperInstance->createDomElement(doc, &_ThreeDSurfacePlotSidebarDataRoot, "IsNormalized", QString::number(m_isNormalized));
            GlobalHelperInstance->createDomElement(doc, &_ThreeDSurfacePlotSidebarDataRoot, "DataSource", m_dataSource);

            element->appendChild(_ThreeDSurfacePlotSidebarDataRoot);

            return _ThreeDSurfacePlotSidebarDataRoot;
        }
        /// @brief 从工程文件读入数据
        void readFromProjectFile(QDomElement* element, bool isdiso = false)
        {
            auto _GraphNameNodeList = element->elementsByTagName("GraphName");
            m_graphName = _GraphNameNodeList.item(0).toElement().text();
            auto _IsGraphNameRenamedNodeList = element->elementsByTagName("IsGraphNameRenamed");
            m_isGraphNameRenamed = (bool)_IsGraphNameRenamedNodeList.item(0).toElement().text().toInt();
            auto _IsShowActorNodeList = element->elementsByTagName("IsShowActor");
            m_isShowActor = (bool)_IsShowActorNodeList.item(0).toElement().text().toInt();

            auto _CurrentScalarArrayCompNodeList = element->elementsByTagName("CurrentScalarArrayComp");
            m_currentScalarArrayComp = (int)_CurrentScalarArrayCompNodeList.item(0).toElement().text().toDouble();
            auto _IsLogNodeList = element->elementsByTagName("IsLog");
            m_isLog = (bool)_IsLogNodeList.item(0).toElement().text().toInt();
            auto _IsNormalizedNodeList = element->elementsByTagName("IsNormalized");
            m_isNormalized = (bool)_IsNormalizedNodeList.item(0).toElement().text().toInt();
            auto _DataSourceNodeList = element->elementsByTagName("DataSource");
            m_dataSource = _DataSourceNodeList.item(0).toElement().text();
        }

    private:
        QString m_graphName = ""; //图名称
        bool m_isGraphNameRenamed = false;//是否有被手动重命名过
        bool m_isShowActor = true;
        QList<FieldGraphGenerator::ArrayInformation> m_allPointArray{};
        QList<FieldGraphGenerator::ArrayInformation> m_allCellArray{};
        FieldGraphGenerator::ArrayInformation m_currentScalarArray{};
        int m_currentScalarArrayComp{ 0 };//分量
        bool m_isLog = false;
        bool m_isNormalized = false;
        QString m_dataSource = "";
    };
}
#endif
